package git.soulbgm.producer.controller;

import git.soulbgm.producer.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 贺瑞杰
 * @version V1.0
 * @date 2018-09-28 10:42
 * @description
 */
@RestController
@Slf4j
public class DemoController {

    @RequestMapping(value = "hello", method = RequestMethod.POST)
    public String hello(@RequestBody User user) {
        return user.toString();
    }

    @RequestMapping(value = "hello2", method = RequestMethod.GET)
    public String hello2(@ModelAttribute User user) {
        return user.toString();
    }

    @RequestMapping("/test")
    public String test(String str) {
        return "hello " + str;
    }

    @RequestMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart("file") MultipartFile file) {
        log.info("文件大小：{}", file.getSize());
        log.info("文件类型：{}", file.getContentType());
        log.info("文件原始的名称：{}", file.getOriginalFilename());
        return file.getOriginalFilename();
    }

}
